package com.exonline.controller.resource;

import com.exonline.base.IBaseService;
import com.exonline.commons.dao.DaoImpl;
import com.exonline.commons.dao.IDao;
import com.exonline.entity.CoursesResource;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class ResourceService implements IBaseService<CoursesResource> {
   IDao<CoursesResource> ResourceManagementDao = new DaoImpl<>();

   // 查询全部
    @Override
    public List<CoursesResource> queryAll(int pageSize, int pageNo) throws SQLException {
        return ResourceManagementDao.queryWithPagingAndConditions("SELECT * FROM role",null,pageNo,pageSize,new BeanListHandler<>(CoursesResource.class));
    }
    // 根据id查询
    @Override
    public CoursesResource queryOneForId(String id) throws SQLException {
        return   ResourceManagementDao.queryForObject("select * from coursesresource where id = ?", new BeanHandler<>(CoursesResource.class), id);
    }
    // 添加
    @Override
    public void add(Object... obj) throws SQLException {
        ResourceManagementDao.updateWithTransaction("INSERT INTO coursesresource(id,cid,videourl) VALUES(?,?,?)",obj);
    }

    // 修改
    @Override
    public void update(Object... obj) throws SQLException {
        ResourceManagementDao.updateWithTransaction("UPDATE coursesresource SET url =? ,WHERE id = ?",obj);
    }
    // 删除
    @Override
    public void deleteById(String id) throws SQLException {
        ResourceManagementDao.updateWithTransaction(" DELETE FROM coursesresource WHERE id = ?",id);
    }
}
